﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace MvcCodeNotes.Models
{
    public class Pagination<T> : List<T>
    {
        public int PageIndex { get; private set; }
        public int PageSize { get; private set; }
        public int TotalCount { get; private set; }

        public int TotalPages { get; private set; }

        public Pagination(List<T> source, int pageIndex, int pageSize)
        {

            PageIndex = pageIndex;

            PageSize = pageSize;

            TotalCount = source.Count();

            // 进上去取整（ 总记录条数/一面记录的条数）

            TotalPages = (int)Math.Ceiling(TotalCount / (double)pageSize);

            this.AddRange(source.Skip(pageIndex * pageSize).Take(PageSize));

        }

        public bool HasPreviousPage
        {
            get { return (PageIndex > 0); }
        }

        public bool HasNextPage
        {
            get { return (PageIndex + 1 < TotalPages); }

        }

    }
}